//
//  CQNewCollectionController.swift
//  weibo
//
//  Created by chengqiang on 16/7/22.
//  Copyright © 2016年 chengqiangBiaodashi. All rights reserved.
//

import UIKit

private let reuseIdentifier = "Cell"
private let ItemCount = 4
class CQNewCollectionController: UICollectionViewController {
    
    
    let layout = UICollectionViewFlowLayout()
    //初始化一个layout
    init(){
        super.init(collectionViewLayout: layout)
    }
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    

    override func viewDidLoad() {
        super.viewDidLoad()

        self.collectionView!.registerClass(CQNewCell.self, forCellWithReuseIdentifier: reuseIdentifier)
        
        setupLayout()

    }
    //设置流水布局
    private func setupLayout(){
        
        layout.itemSize=self.view.frame.size
        layout.minimumLineSpacing=0
        layout.minimumInteritemSpacing=0
        
        layout.scrollDirection=UICollectionViewScrollDirection.Horizontal
        collectionView?.pagingEnabled=true
        collectionView?.bounces=false
    }


    // MARK: -数据源方法

    override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {

        return ItemCount
    }

    override func collectionView(collectionView: UICollectionView,cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath)as! CQNewCell
    
//        cell.backgroundColor=UIColor.randomColor()
        cell.image = UIImage(named: "new_feature_\(indexPath.item + 1)")
        if indexPath.item == ItemCount-1
        {
            cell.showButton(true)
        }
        else{
            cell.showButton(false)
        }
        
        return cell
    }


}
